/**
 * Copyright 2008 Matthew DeLambo
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.delambo.drool.interfaces;

import java.util.concurrent.atomic.*;

public interface AtomicLockingArray<E> {

    interface Factory {
        AtomicLockingArray create(int size);
    }
    
    /**
     * Tries to atomically lock the given index in this array.  
     * @param index allocation of pool to lock.
     * @return true if lock succeeds; otherwise, false.
     */
    public boolean tryLock(int index);    
    
    /**
     * Locks the given index in this array.
     * @param index allocation of array.
     */
    public void lock(int index);
    
    /**
     * Unlocks the specified index in this array.
     * @param slot allocation in object pool to lock.
     */
    public void unlock(int index);
    
    /**
     * Indicates whether or not a thread has a lock on the given index.
     * @param slot allocation in locked array.
     * @return true if slot is locked by another thread; otherwise, false.
     */
    public boolean locked(int index);
    
    /**
     * Returns the size of this array
     */
    public int getSize();
    
    /**
     * Gets a node from the array.
     */
    public E getNode(int index);
    
    /**
     * Sets a node into the array.
     */
    public void setNode(int index, E e);
}

